﻿using QD.SQLHelper;
using QD.Tools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QD.DbManager
{
    public partial class DbLogSizeMag : DbBasic
    {
        EFDbContext dbContext;
        LogonConfig logonConfig;

        public DbLogSizeMag(LogonConfig logonConfig)
        {
            InitializeComponent();

            this.logonConfig = logonConfig;

            DataGridViewHelper.InitGrid(this.grid);
            this.grid.RowTemplate.ContextMenuStrip = this.contextMenuStrip1;
        }

        private void DbLogSizeMag_Load(object sender, EventArgs e)
        {
            dbContext = new EFDbContext(logonConfig.GetConnectionStrings("master"));

            Grid_DataBind();
        }

        private void Grid_DataBind()
        {
            DataTable dt = dbContext.Query("dbcc sqlperf(logspace)");
            dt.Columns["Database Name"].ColumnName = "DatabaseName";
            dt.Columns["Log Size (MB)"].ColumnName = "LogSize";
            dt.Columns["Log Space Used (%)"].ColumnName = "LogSpaceUsed";


            this.grid.DataSource = dt;
        }

        private void 复制单元格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.grid.CopyFirstSelectedCellValue();
        }

        private void 复制所有选中单元格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.grid.CopySelectedCellsValue();
        }
    }
}
